/*
 * @Description: 
 * @Author: mmzhang
 * @Date: 2021-12-10 16:52:09
 * @LastEditTime: 2022-02-22 09:54:27
 */
import Opt from '@/components/dt/info/Opt.js'
import businessCommonMgr from '@/biz/businessReport/businessCommon'
import dateOpt from '@/biz/option/date.js'
import ruleOpt from '@/biz/option/rule.js'
import tool from '@/common/tool.js'
import clueMgr from '@/biz/businessReport/clue'
import houseOpt from '@/biz/option/house.js'
import nameOpt from '@/biz/option/name.js'
import crimeOpt from './listOpt'
import dt from '@dt/dt'
let _this = null


class SearchOpt extends Opt {

  constructor(vm) {
    _this = vm
    super()
    this.build()
  }

  getCompany(keyVal, labelVal) {
    let companys = []
    let opt = {
      title: labelVal,
      key: keyVal,
      placeholder: '全部',
      tree: {
        options: companys,
      }
    }
    let params = {
      isTwoLevel: true,
    }
    businessCommonMgr
      .getOrgThreeTree(params)
      .then((res) => {
        console.log(res, 'aaaaaaaaaaaaaa');
        companys = res
        opt.tree.options = companys
      })
    return opt
  }
  getCompany1(keyVal, labelVal) {
    let companys1 = []
    let opt = {
      title: labelVal,
      key: keyVal,
      placeholder: '全部',
      tree: {
        options: companys1,
      }
    }
    let params = {
      isTwoLevel: true,
    }
    businessCommonMgr
      .getOrgThreeTree(params)
      .then((res) => {
        console.log(res, 'aaaaaaaaaaaaaa');
        companys1 = res
        opt.tree.options = companys1
      })
    return opt
  }
  getOACompany() {
    let oaCompanys = []
    let opt = {
      title: 'OA组织',
      key: 'oaIds',
      placeholder: '全部',
      tree: {
        options: oaCompanys,
      }
    }
    let params = {
      appId: dt.userInfo().appId,
      userId: dt.userInfo().userId,
      roleId: dt.userInfo().role.roleId,
      delFlag: 2
    }
    businessCommonMgr
      .getOA(params)
      .then((res) => {
        console.log(res, 'oa组织树11');
        oaCompanys = res
        opt.tree.options = oaCompanys
      })
    return opt
  }


  build() {
    this.createAll()
    this.opts.push(...this.all)
  }


  createAll() {
    this.all = [
      this.getCompany('outOrgIds', '移出组织'),
      this.getCompany1('inOrgIds', '移入组织'),
      this.getOACompany(),
      houseOpt.create({
        title: '案场名称',
        placeholder: '请输入案场名称',
        to: (info) => {
          console.log(info, 'infoffffffffffff');
          return {
            buildingName: info.housesName,
            buildingId: info.housesId
          }
        }
      }),

      {
        title: '操作日期',
        key: 'time',
        placeholder: '请选择日期',
        date: {
          type: 'daterange',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          }
        },
        rules: [
          ruleOpt.check('日期跨度至多两年', (value) => {
            console.log(value, '33333333333333');
            return value.length && tool.dateDiff(value[0], value[1]).Y >= 2
          })
        ]
      },

    ]
  }
}

export default SearchOpt